package cn.openea.perpartner.expert.rabbit;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.openea.perpartner.expert.web.domain.dto.TimelineDto;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Weird077
 * @description 时间轴消息生产者
 * @date 2023-07-07 11:59
 */
@Slf4j
@Component
public class TimelineProducer {
    @Resource
    private RabbitTemplate rabbitTemplate;
    private static final String EXCHANGE = "timeline.business.exchange";
    private static final String ROUTE_KEY = "timeline.business.routing.key";

    public void execute(TimelineDto dto) {
        if (BeanUtil.isEmpty(dto)) {
            return;
        }
        if (StrUtil.isBlank(dto.getType())){
            dto.setType("timeline");
        }
        rabbitTemplate.convertAndSend(EXCHANGE, ROUTE_KEY, JSON.toJSON(dto));
        log.info("{},{}时间轴消息于{}发送成功！{}", dto.getTicketNum(),dto.getEventTitle(),DateUtil.now(),dto);
    }

}

